package com.gzk.basic.controller;

import com.gzk.basic.exception.BusinessException;
import com.gzk.basic.service.IVerifyService;
import com.gzk.basic.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/verifyCode")
public class VerifyCodeController {

    @Autowired
    private IVerifyService verifyService;


    /**
     * 手机端验证码
     * @return
     */
    @PostMapping("/phoneCode")
    public AjaxResult phoneCode(@RequestBody Map<String,String> map){
        try {
            verifyService.phoneCode(map);
            return AjaxResult.ok();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.ok().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.ok();
    }

    @PostMapping("/emailCode")
    public AjaxResult emailCode(@RequestBody Map<String,String> map){
        try {
            verifyService.emailCode(map.get("email"));
            return AjaxResult.ok();
        } catch (BusinessException e) {
            e.printStackTrace();
            return AjaxResult.ok().setSuccess(false).setMessage(e.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
        }
        return AjaxResult.ok();
    }
}
